<template>
  <view class="tarbar-box" :class="shadow ? 'shadow' : ''">
    <view class="shoptab">
      <view class="box">
        <view class="item" v-for="(item, i) in pages" :key="i" @click="rTourl(item.path, item.id, item)">
          <image v-if="index == item.id" :src="$img_base_url(item.selectImage)" mode="widthFix"></image>
          <image v-else :src="$img_base_url(item.image)" mode="widthFix"></image>
          <text :class="index == item.id ? 'select' : ''">{{ item.text }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import tarbarList from "./list.json";
export default {
  name: "shopTarbar",
  props: {
    index: {
      type: String,
      default: "1",
    },
    page: {
      type: String,
      default: "1", //1服务，2商城，3课程
    },
    shadow: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      pages: tarbarList[this.page],
    };
  },

  methods: {
    rTourl(url, id, item) {
      console.log(item.index);
      // item.index 跳转首页的标识，用来显示是哪个服务 1服务 3商城 2课程
      if (item.index) {
        uni.setStorageSync("tarbarModule", Number(item.index));
      }
      uni.redirectTo({
        url,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.tarbar-box {
  width: 100%;
  height: calc(118rpx + constant(safe-area-inset-bottom));
  height: calc(118rpx + env(safe-area-inset-bottom));
}
.shoptab {
  width: 100%;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 99;
  background: #ffffff;

  padding-bottom: calc(constant(safe-area-inset-bottom));
  padding-bottom: calc(env(safe-area-inset-bottom));
  .shadow {
    box-shadow: 0rpx -4rpx 8rpx 2rpx rgba(0, 0, 0, 0.05);
  }
  .box {
    display: flex;
    padding: 16rpx 0rpx 4rpx;
    width: 100%;
    box-sizing: border-box;
    justify-content: space-between;
    .item {
      width: 25%;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      image {
        width: 48rpx;
        height: 48rpx;
      }
      text {
        font-weight: 400;
        font-size: 24rpx;
        color: #999999;
        line-height: 34rpx;
        margin-top: 2rpx;
        &.select {
          color: #e72a2a;
        }
      }
    }
  }
}
</style>
